<?php
class countryModel extends appModel{
    
    protected function init(){
        
    }
    public function read($id=false){       
        $data = array();
        $q = "";
        if(!empty($id)){
            $q = "WHERE `id`={$id}";
        }
        $start = isset($_GET['start']) ? $_GET['start'] : 0;
        $limit = isset($_GET['limit']) ? $_GET['limit'] : 10;
        $query = "SELECT * FROM `users` {$q} ORDER BY `username` DESC LIMIT {$start},{$limit}";

        $result = $this->db->query($query);
        
        $nbrows = $this->db->fetchRow($this->db->query("SELECT COUNT(*) FROM `users`"));
        $nbrows = $nbrows[0];
        while($row=$this->db->fetchAssoc($result)){
            $data[]=$row;
        }
// print_r($data);
        if(MyHelpers::isAjax()){
            // prepare the metadata
            $ret['metaData'] =   $this->makeMetaData($result);
            $ret['total']    =   $nbrows;
            $ret['data']     =   $this->Char2Utf8($data);
            $ret['success']  =   true;
            $ret['message']  =   true;
            return json_encode($ret);
        }
        return $data;       
    }
    public function CountryName($id,$country_id,$code,$create_date,$modified,$name){
        $id = false;
        
        $result = $this->db->query("INSERT INTO country (country_id, code, create_date, modified, name) VALUES ('$country_id', '$code', '$create_date', '$modified', '$name')");
        if($result != false){
            $id = $this->db->insertId();
        }

        return $id;
    }

}
?>